package com.shiyue.cqe.bean;

import java.io.Serializable;

/**
 * equals() and hashCode();
 * @author gangzi
 */
public abstract class BaseObject implements Serializable {
	@SuppressWarnings("unchecked")
	private Comparable orderField; //作为临时排序字段使用
	private static final long serialVersionUID = -3658698824540003392L;
	
	/**
	 * @return 数据的真实ID，不加get方法减少相关反射输出
	 */
	public abstract Serializable realId();
	
	public final int hashCode() {
		return (realId() == null) ? 0 : realId().hashCode();
	}
	
	public final boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (getClass() != obj.getClass())
			return false;
		BaseObject other = (BaseObject) obj;
		return !(this.realId() != null ? !(this.realId().equals(other.realId())) : (other.realId() != null));
	}
	
	@SuppressWarnings("unchecked")
	public Comparable getOrderField() {
		return orderField;
	}
	@SuppressWarnings("unchecked")
	public void setOrderField(Comparable orderField) {
		this.orderField = orderField;
	}
}
